/*
 * cadastroFuncionarios.java
 *
 * Created on 30 de Outubro de 2007, 02:02
 */

package cadastro;

import bd.Database;
import classes.funcionarios;
import classes.Util;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.MaskFormatter;
/**
 *
 * @author  kurumin
 */
public class cadFuncionarios extends javax.swing.JFrame {
    private Database bd;
    /** Creates new form cadastroFuncionarios */
    public cadFuncionarios(Database meuBd) {
        initComponents();
        this.bd = meuBd;
        f = new funcionarios(this.bd);
        preenchecombo();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jtFuncionarios = new javax.swing.JTabbedPane();
        jpConsFunc = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        rbcodigo = new javax.swing.JRadioButton();
        rbnome = new javax.swing.JRadioButton();
        rbcargo = new javax.swing.JRadioButton();
        jtfPesquisar = new javax.swing.JTextField();
        botaoPesquisar = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtfuncionarios = new javax.swing.JTable();
        botaoEditar = new javax.swing.JButton();
        jpCadFunc = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtfNome = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtfRg = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtfCpf = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        rbotaoM = new javax.swing.JRadioButton();
        rbotaoF = new javax.swing.JRadioButton();
        jLabel5 = new javax.swing.JLabel();
        jtfCargo = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jtfTelefone = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jtfCelular = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jtfEmail = new javax.swing.JTextField();
        try
        {
            formatadata = new MaskFormatter("##/##/####");
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null,"hehehe");
        }
        jtfdatanasc = new JFormattedTextField(formatadata);
        try
        {
            formatadataadm = new MaskFormatter("##/##/####");
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null,"hehehhehe");
        }
        jtfdataadm = new JFormattedTextField(formatadataadm);
        jPanel3 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jtfLogradouro = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jtfBairro = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jtfCidade = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jcvUF = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jtfCep = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        botaoCadastrar = new javax.swing.JButton();
        botaoNovo = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de funcionarios");
        setResizable(false);

        jtFuncionarios.setToolTipText("");
        jtFuncionarios.setFont(new java.awt.Font("Dialog", 0, 12));

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Localizar"));

        buttonGroup1.add(rbcodigo);
        rbcodigo.setFont(new java.awt.Font("Dialog", 0, 12));
        rbcodigo.setSelected(true);
        rbcodigo.setText("Código");
        rbcodigo.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        buttonGroup1.add(rbnome);
        rbnome.setFont(new java.awt.Font("Dialog", 0, 12));
        rbnome.setText("Nome");
        rbnome.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        buttonGroup1.add(rbcargo);
        rbcargo.setFont(new java.awt.Font("Dialog", 0, 12));
        rbcargo.setText("Cargo");
        rbcargo.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(rbcodigo)
                .addGap(70, 70, 70)
                .addComponent(rbnome)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 97, Short.MAX_VALUE)
                .addComponent(rbcargo)
                .addGap(55, 55, 55))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbcodigo)
                    .addComponent(rbcargo)
                    .addComponent(rbnome))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        botaoPesquisar.setText("Pesquisar");
        botaoPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoPesquisarActionPerformed(evt);
            }
        });

        jLabel15.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel15.setText("Pesquisar");

        jtfuncionarios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jtfuncionarios);

        botaoEditar.setText("Editar");
        botaoEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoEditarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpConsFuncLayout = new javax.swing.GroupLayout(jpConsFunc);
        jpConsFunc.setLayout(jpConsFuncLayout);
        jpConsFuncLayout.setHorizontalGroup(
            jpConsFuncLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jpConsFuncLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jtfPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 286, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoPesquisar)
                .addGap(21, 21, 21))
            .addGroup(jpConsFuncLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel15)
                .addContainerGap(369, Short.MAX_VALUE))
            .addGroup(jpConsFuncLayout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpConsFuncLayout.createSequentialGroup()
                .addContainerGap(331, Short.MAX_VALUE)
                .addComponent(botaoEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jpConsFuncLayout.setVerticalGroup(
            jpConsFuncLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpConsFuncLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel15)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpConsFuncLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoPesquisar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoEditar)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jtFuncionarios.addTab("Consulta", jpConsFunc);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel1.setText("Nome");

        jLabel2.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel2.setText("CPF");

        jLabel3.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel3.setText("RG");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Sexo"));

        buttonGroup2.add(rbotaoM);
        rbotaoM.setSelected(true);
        rbotaoM.setText("M");
        rbotaoM.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        buttonGroup2.add(rbotaoF);
        rbotaoF.setText("F");
        rbotaoF.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(rbotaoM)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbotaoF)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(rbotaoF)
                .addComponent(rbotaoM))
        );

        jLabel5.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel5.setText("Cargo");

        jLabel13.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel13.setText("Data Nasc.");

        jLabel14.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel14.setText("Data Admissão");

        jLabel11.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel11.setText("Telefone");

        jLabel12.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel12.setText("Celular");

        jLabel10.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel10.setText("Email");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jtfRg, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(12, 12, 12)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jtfCargo, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(jtfdatanasc, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel14)
                            .addComponent(jtfdataadm, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jtfTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                                .addComponent(jtfCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addGap(53, 53, 53)
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 68, Short.MAX_VALUE))))
                    .addComponent(jtfNome, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jtfEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 418, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfNome, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfRg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfCargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jLabel14)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfdatanasc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfdataadm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Endereço"));

        jLabel4.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel4.setText("Logradouro");

        jLabel6.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel6.setText("Bairro");

        jLabel7.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel7.setText("Cidade");

        jLabel8.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel8.setText("UF");

        jLabel9.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel9.setText("Cep");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jtfBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jcvUF, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addGap(16, 16, 16)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfCep, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)
                            .addComponent(jLabel9)))
                    .addComponent(jtfLogradouro, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE)
                    .addComponent(jLabel4))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfLogradouro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcvUF, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(29, Short.MAX_VALUE))
        );

        jPanel4.setBackground(new java.awt.Color(204, 204, 204));
        jPanel4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel4.setForeground(new java.awt.Color(204, 204, 204));

        botaoCadastrar.setMnemonic('G');
        botaoCadastrar.setText("Gravar");
        botaoCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoCadastrarActionPerformed(evt);
            }
        });

        botaoNovo.setMnemonic('N');
        botaoNovo.setText("Novo");
        botaoNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoNovoActionPerformed(evt);
            }
        });

        jButton1.setMnemonic('D');
        jButton1.setText("Deletar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(158, Short.MAX_VALUE)
                .addComponent(botaoNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addGap(6, 6, 6)
                .addComponent(botaoCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoCadastrar)
                    .addComponent(botaoNovo)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jpCadFuncLayout = new javax.swing.GroupLayout(jpCadFunc);
        jpCadFunc.setLayout(jpCadFuncLayout);
        jpCadFuncLayout.setHorizontalGroup(
            jpCadFuncLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpCadFuncLayout.createSequentialGroup()
                .addGroup(jpCadFuncLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jpCadFuncLayout.setVerticalGroup(
            jpCadFuncLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpCadFuncLayout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jtFuncionarios.addTab("Cadastro", jpCadFunc);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jtFuncionarios, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jtFuncionarios, javax.swing.GroupLayout.PREFERRED_SIZE, 481, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-447)/2, (screenSize.height-513)/2, 447, 513);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
      
    }//GEN-LAST:event_jButton1ActionPerformed

    private void botaoEditarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaoEditarActionPerformed
    {//GEN-HEADEREND:event_botaoEditarActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        editar();
    }//GEN-LAST:event_botaoEditarActionPerformed

    private void botaoPesquisarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaoPesquisarActionPerformed
    {//GEN-HEADEREND:event_botaoPesquisarActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        pesquisa();
    }//GEN-LAST:event_botaoPesquisarActionPerformed

    private void botaoNovoActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaoNovoActionPerformed
    {//GEN-HEADEREND:event_botaoNovoActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        limpar();
        grava = true;
    }//GEN-LAST:event_botaoNovoActionPerformed

    private void botaoCadastrarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaoCadastrarActionPerformed
    {//GEN-HEADEREND:event_botaoCadastrarActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
         cadastrar();
    }//GEN-LAST:event_botaoCadastrarActionPerformed
    
    private void cadastrar()
    {
        f.setNome(jtfNome.getText());
        f.setBairro(jtfBairro.getText());
        f.setCargo(jtfCargo.getText());
        f.setCelular(jtfCelular.getText());
        f.setCidade(jtfCidade.getText());
        f.setCpf(jtfCpf.getText());
        f.setData_admissao(jtfdataadm.getText());
        f.setEmail(jtfEmail.getText());
        f.setEndereco(jtfLogradouro.getText());
        f.setTelefone(jtfTelefone.getText());
        f.setRg(jtfRg.getText());
        f.setEstado((String) this.jcvUF.getSelectedItem());
        if(rbotaoF.isSelected())
            f.setSexo("F");
        else
            f.setSexo("M");
        if(grava){
            if(f.gravar())
               mensagem = "Registro salvo com sucesso";
            else
               mensagem = "Erro ao tentar gravar o registro";
        }  
        else{
            if(f.atualizar())
                mensagem = "Registro salvo com sucesso";
            else
               mensagem = "Erro ao tentar gravar o registro";
        }
        JOptionPane.showMessageDialog(null,mensagem);         
    }
    private void pesquisa()
    {
        String[] colunas = new String[]{"C?digo","Nome","Cargo"};  
        String[][] dados = new String[][]{{}};
        funcionario = new DefaultTableModel(dados,colunas);
        String sql;
        ResultSet rs;
        String parametro;
        if(rbcargo.isSelected())
            parametro = "cargo";
        else if(rbcodigo.isSelected())
            parametro = "id_funcionario";
        else
            parametro = "nome";
        try
        {
            sql= "SELECT funcionario.id_funcionario, funcionario.nome, funcionario.cargo FROM funcionario WHERE LOWER(funcionario."+parametro+") LIKE LOWER('%"+jtfPesquisar.getText()+"%')";
            rs = bd.executeQueryRs(sql);
            if(bd.Error){
                JOptionPane.showMessageDialog(null,bd.ErrorMessage);
                return;
            }
            String func[] = new String[4];
            int aux = 0;
            while( rs.next())
            {
                func[0] = rs.getString("id_funcionario");
                func[1] = rs.getString("nome");
                func[2] = rs.getString("cargo");
                funcionario.addRow(func);     
                if (aux == 0){
                    funcionario.removeRow(0);
                }
                aux++;
            }
            jtfuncionarios.setModel(funcionario);
            
        }
        catch(SQLException e)
        {
            JOptionPane.showMessageDialog(null,e);
        }
    }
    @SuppressWarnings("static-access")
    private void editar()
    {
         int  l = jtfuncionarios.getSelectedRow();
         String id = jtfuncionarios.getValueAt(l,0).toString();
         Util aux = new Util();
         
         f.setId(id);
         f.obter();
         limpar();
         jtfBairro.setText(f.getBairro());
         jtfCargo.setText(f.getCargo());
         jtfCelular.setText(f.getCelular());
        
         jtfCidade.setText(f.getCidade());
         jtfCpf.setText(f.getCpf());
         jtfdataadm.setText(f.getData_admissao());
         jtfEmail.setText(f.getEmail());
         jtfLogradouro.setText(f.getEndereco());
         jtfNome.setText(f.getNome());
         jtfRg.setText(f.getrg());
         jtfTelefone.setText(f.getTelefone());
         jcvUF.setSelectedIndex(aux.posicao(f.getEstado(),estados));
         jtFuncionarios.setSelectedIndex(1);
         grava=false;        
    } 
    private void limpar()
    {
        jtfBairro.setText("");
        jtfCargo.setText("");
        jtfCelular.setText("");
        jtfCep.setText("");
        jtfCidade.setText("");
        jtfCpf.setText("");
        jtfdataadm.setText("");
        jtfdatanasc.setText("");
        jtfEmail.setText("");
        jtfLogradouro.setText("");
        jtfNome.setText("");
        jtfPesquisar.setText("");
        jtfRg.setText("");
        jtfTelefone.setText("");
        rbotaoM.setSelected(true);
        jcvUF.setSelectedIndex(1);
        funcionario = (DefaultTableModel) jtfuncionarios.getModel();  
        funcionario.setNumRows(0);  
    }
    
    private void preenchecombo()
    {
        ResultSet rs = bd.executeQueryRs("Select estado from estado");
        try {
            while (rs.next()){
                jcvUF.addItem(rs.getString(1));
                estados.add(rs.getString(1));
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoCadastrar;
    private javax.swing.JButton botaoEditar;
    private javax.swing.JButton botaoNovo;
    private javax.swing.JButton botaoPesquisar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jcvUF;
    private javax.swing.JPanel jpCadFunc;
    private javax.swing.JPanel jpConsFunc;
    private javax.swing.JTabbedPane jtFuncionarios;
    private javax.swing.JTextField jtfBairro;
    private javax.swing.JTextField jtfCargo;
    private javax.swing.JTextField jtfCelular;
    private javax.swing.JTextField jtfCep;
    private javax.swing.JTextField jtfCidade;
    private javax.swing.JTextField jtfCpf;
    private javax.swing.JTextField jtfEmail;
    private javax.swing.JTextField jtfLogradouro;
    private javax.swing.JTextField jtfNome;
    private javax.swing.JTextField jtfPesquisar;
    private javax.swing.JTextField jtfRg;
    private javax.swing.JTextField jtfTelefone;
    private javax.swing.JFormattedTextField jtfdataadm;
    private javax.swing.JFormattedTextField jtfdatanasc;
    private javax.swing.JTable jtfuncionarios;
    private javax.swing.JRadioButton rbcargo;
    private javax.swing.JRadioButton rbcodigo;
    private javax.swing.JRadioButton rbnome;
    private javax.swing.JRadioButton rbotaoF;
    private javax.swing.JRadioButton rbotaoM;
    // End of variables declaration//GEN-END:variables
    private funcionarios f;
    DefaultTableModel funcionario;
    private ArrayList <String> estados = new ArrayList <String>();
    private boolean grava = true;
    private MaskFormatter formatadata,formatadataadm;
    private String  mensagem;
}
